package com.msb.test12;

import java.util.ArrayList;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int choice;
        ArrayList books = new ArrayList();

        while (true){
            choice = showMenu(scanner);
            if (choice> 4){break;}
            switch (choice) {
                case 1:{
                    showBook(books);
                    break;
                }
                case 2:{
                    addBook(books,scanner);
                    break;
                }
                case 3:{
                    removeBook(books,scanner);
                    break;
                }
                case 4:{
                    break;
                }
            }




        }

    }
    public static int showMenu(Scanner scanner){
        System.out.println("欢迎来到【老马书城】");
        System.out.println("1.展示书籍");
        System.out.println("2.上新书籍");
        System.out.println("3.下架书籍");
        System.out.println("4.退出应用");
        System.out.println("请选择您的操作：");
        int number = scanner.nextInt();
//        scanner.nextLine();
        return number;

    }

    public static void showBook(ArrayList books) {
        System.out.println(books);

    }

    public static void addBook(ArrayList books,Scanner scanner) {
        System.out.println("请输入书籍编号");
        int bNo = scanner.nextInt();
        scanner.nextLine();
        System.out.println("请输入书籍名称");
        String bName = scanner.nextLine();
        System.out.println("请输入书籍作者");
        String bAuthor = scanner.nextLine();
        Book book = new Book(bNo,bName,bAuthor);
        books.add(book);
        System.out.println(books);

    }

    public static void removeBook(ArrayList books,Scanner scanner ) {
        System.out.println("请输入书籍名称");
        String book = scanner.nextLine();
        for (int i = 0; i < books.size(); i++) {
            if (books.get(i).equals(book)) {
                books.remove(book);
            }
        }

        System.out.println(books);

    }
}
